﻿package mortal.game.view.guild.redPack
{
    import Message.Game.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.manager.msgTip.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.mvc.core.*;

    public class RedPackGivePanel extends GSprite
    {
        private var _giveRedPackBtn:GLoadingButton;
        private var _giveAgainRedPackBtn:GLoadingButton;
        private var _leftMoney:GTextFiled;
        private var _lastSystemGiveDate:Number = 0;
        private var _lastSelfGiveDate:Number = 0;
        private var _sRedEvnvelopInfo:SRedEnvelopeInfo;

        public function RedPackGivePanel()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.RedPackSimpleTxt_2, 115, 342, this));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.RedPackTxt_1, 102, 152, this));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.RedPackSimpleTxt_1, 123, 110, this));
            this._giveRedPackBtn = UIFactory.gLoadingButton(ResFileConst.RedPackGiveBtn, 144, 462, 131, 44, this);
            this._giveRedPackBtn.configEventListener(MouseEvent.CLICK, this.giveRedPack);
            this._giveAgainRedPackBtn = UIFactory.gLoadingButton(ResFileConst.ZfychbBtn, 144, 462, 131, 44, this);
            this._giveAgainRedPackBtn.visible = false;
            this._giveAgainRedPackBtn.configEventListener(MouseEvent.CLICK, this.giveAgainRedPackBtn);
            var _loc_1:* = GlobalStyle.textFormatLv.center();
            _loc_1.size = 16;
            this._leftMoney = UIFactory.gTextField("", 101, 354, 167, 40, this, _loc_1);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._giveAgainRedPackBtn.dispose(param1);
            this._giveAgainRedPackBtn = null;
            this._giveRedPackBtn.dispose(param1);
            this._giveRedPackBtn = null;
            this._leftMoney.dispose(param1);
            this._leftMoney = null;
            this._sRedEvnvelopInfo = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function giveAgainRedPackBtn(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.RedPackSelfGiveWinOpen, null));
            return;
        }// end function

        private function giveRedPack(event:MouseEvent) : void
        {
            var _loc_2:Number = NaN;
            var _loc_5:Number = NaN;
            var _loc_6:Date = null;
            var _loc_3:Boolean = true;
            var _loc_4:* = Cache.instance.redPackCache.redPackState;
            if (_loc_4 == RedPackStateType.CanGive)
            {
                if (this._lastSystemGiveDate == 0)
                {
                    this._lastSystemGiveDate = ClockManager.instance.nowDate.time;
                    _loc_3 = false;
                }
                _loc_2 = this._lastSystemGiveDate;
            }
            else
            {
                if (this._lastSelfGiveDate == 0)
                {
                    this._lastSelfGiveDate = ClockManager.instance.nowDate.time;
                    _loc_3 = false;
                }
                _loc_2 = this._lastSelfGiveDate;
            }
            if (_loc_3)
            {
                _loc_5 = ClockManager.instance.nowDate.time;
                if (_loc_5 - _loc_2 < 60000)
                {
                    return MsgManager.showRollTipsMsg(Language.getString(21502), MsgRollTipsType.msgRollTips3);
                }
                if (_loc_4 == RedPackStateType.CanGive)
                {
                    this._lastSystemGiveDate = _loc_5;
                }
                else
                {
                    this._lastSelfGiveDate = _loc_5;
                }
            }
            if (this._sRedEvnvelopInfo)
            {
                _loc_6 = ClockManager.instance.nowDate;
                if (_loc_6.time > this._sRedEvnvelopInfo.effectDay.time)
                {
                    return MsgManager.showRollTipsMsg(Language.getString(21503), MsgRollTipsType.msgRollTips3);
                }
                GameProxy.guild.repostRedEnvelope(this._sRedEvnvelopInfo.redId);
            }
            else
            {
                GameProxy.guild.giveRedEnvelope(0, 300, 8);
            }
            RedPacketWin.instance.hide();
            return;
        }// end function

        public function updateType(param1:SRedEnvelopeInfo) : void
        {
            var _loc_2:int = 0;
            this._sRedEvnvelopInfo = param1;
            if (this._sRedEvnvelopInfo)
            {
                _loc_2 = Cache.instance.redPackCache.getRedPackMoney(this._sRedEvnvelopInfo.type);
                this._giveRedPackBtn.visible = _loc_2 > 0;
                this._giveAgainRedPackBtn.visible = _loc_2 <= 0;
            }
            else
            {
                _loc_2 = Cache.instance.redPackCache.getRedPackMoney();
                this._giveRedPackBtn.visible = true;
                this._giveAgainRedPackBtn.visible = false;
            }
            this._leftMoney.text = _loc_2.toString();
            return;
        }// end function

    }
}
